//
//  WKWebControlM.m
//  
//  jhf
//
//  Created by Mac on 2020/7/31.
//

#import "WKWebControlM.h"

#import <CooperSDK/CooperSDK.h>
#import <CooperSDK/NSString+JCategory.h>

@implementation WKWebControlM

// html 未处理片段
+ (WKWebControlM *)defaultControlWebContent:(NSString *)content; {
    WKWebControlM *model = [[WKWebControlM alloc] init];
    model.htmlContent = [content convertToHtmlMeta:true adjustSizePx:15 adjustColorHex:nil adjustImgsWidth:true];
    return model;
}

// html 片段
+ (WKWebControlM *)defaultControlWebContent:(NSString *)content baseUrl:(NSString *)baseUrl; {
    WKWebControlM *model = [[WKWebControlM alloc] init];
    model.htmlContent = content;
    model.baseUrl = baseUrl;
    return model;
}


// html url
+ (WKWebControlM *)defaultControlUrl:(NSString *)url; {
    WKWebControlM *model = [[WKWebControlM alloc] init];
    model.url = url;
    return model;
}

- (void)controlWebV:(WKWebView *)webV; {
    if (self.url) {
        [webV loadRequest:[NSURLRequest requestWithURL:cp_imageUrl(self.url)]];
    }
    if (self.htmlContent) {
        [webV loadHTMLString:self.htmlContent baseURL:cp_imageUrl(self.baseUrl ?: @"")];
    }
    webV.userInteractionEnabled = self.userInteractionEnabled;
}

@end
